﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#if 0
//结构体
//描述一本书
typedef struct book
{
	char book_name[50];//书名
	char book_atuor[20];//作者
	float price; //价格
	char id[25]; //书号
}book;

int main()
{
	book s1 = { "三国演义","吴承恩",18.8,"FX10001" };
	book s2 = { .book_name = "狂人日记",.book_atuor = "鲁迅",.price = 8.8,.id = "FX10002" };
	printf("%s %s %.1f %s\n", s1.book_name, s1.book_atuor, s1.price, s1.id);
	printf("%s %s %.1f %s\n", s2.book_name, s2.book_atuor, s2.price, s2.id);
	return 0;
}
#endif

#if 0
//结构的自引用
struct Node
{
	int data;
	struct Node* next;
};

typedef struct Node
{
	int data;
	struct Node* next;
}Node;
#endif

//1.结构体类型的声明
/*struct tag
{
	member-list;
}variable-list;*/

#if 0
//结构的特殊声明
struct
{
	int a;
	char b;
	float c;
}x;

struct
{
	int a;
	char b;
	float c;
}a[20],*p;


/*警告：
编译器会把上⾯的两个声明当成完全不同的两个类型，所以是⾮法的。
匿名的结构体类型，如果没有对结构体类型重命名的话，基本上只能使⽤⼀次。*/
#endif

#if 0
//描述一本书
struct book
{
	char book_name[50];//书名
	char book_atuor[20];//作者
	float price; //价格
	char id[25]; //书号
};

int main()
{
	struct book s1 = { "三国演义","吴承恩",18.8,"FX10001" };
	struct book s2 = { .book_name = "狂人日记",.book_atuor = "鲁迅",.price = 8.8,.id = "FX10002" };
	printf("%s %s %.1f %s\n", s1.book_name, s1.book_atuor, s1.price, s1.id);
	printf("%s %s %.1f %s\n", s2.book_name, s2.book_atuor, s2.price, s2.id);
	return 0;
}
#endif


#if 0
// atoi 函数
int my_atoi(const char* str1)
{
	//断言，防止空指针
	assert(str1);
	const char* tmp = str1;
	//跳过空字符
	while (*tmp == ' ')
		tmp++;
	int num = 0;
	while (*tmp <= 57 && *tmp >= 48)
	{
		num = num * 10 + (*tmp - '0');

		if (*(tmp + 1) < 48 || *(tmp + 1) > 57)
		{
			return num;
		}
		tmp++;
	}
	return 0;
}
int main()
{
	char str1[] = "  1234@564";
	int ret1 = my_atoi(str1);
	//int ret2 = atoi(str1);
	printf("%d\n", ret1);
	//printf("%d\n", ret2);
	return 0;
}
#endif